<?php

namespace App\Console\Commands;

use App\Models\FrontendUser;
use App\Services\WalletService;
use Illuminate\Console\Command;

class WalletCheckCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'wallet:check';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '检测钱包地址';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        set_time_limit(0);
        $fontend_user = FrontendUser::where('wallet_address', '')->limit(500)->get();

        foreach ($fontend_user as $k => $v) {
            if (empty($v->password)) {
                $v->password = \Hash::make('123456');
            }

            $v->wallet_address = (new WalletService())->openWallet($v->mobile);

            $v->save();
        }

        return Command::SUCCESS;
    }
}
